package com.jasonzqshen.ifm.featureModelCore.shapes;

import org.w3c.dom.Element;

public class FMCircle {
    private static final String XML_RADIUS = "Radius";

    private double radius;

    private FMPoint center;

    public FMCircle() {
        this.radius = -1;
        this.center = new FMPoint();
    }

    public FMCircle(double radius, FMPoint center) {
        this.radius = radius;
        this.center = center;
    }

    public void toXElem(Element xelem) {
        center.toXElem(xelem);
        xelem.setAttribute(XML_RADIUS, ((Double) radius).toString());
    }

    public static FMCircle parseXElem(Element xelem) {
        FMPoint center = FMPoint.parseXElem(xelem);
        double radius = -1;

        String rStr = xelem.getAttribute(XML_RADIUS);
        try {
            radius = Double.parseDouble(rStr);
        } catch (NumberFormatException e) {
            return new FMCircle(-1, center);
        }

        return new FMCircle(radius, center);
    }

    public double getRadius() {
        return this.radius;
    }

    public FMPoint getCenter() {
        return this.center;
    }
}
